﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Windows;

namespace MockupDesigner.AppItems.Commands
{
    public class CopyCommand : ICommand
    {
        private DesignerCanvas designerCanvas;

        public CommandType CommandType
        {
            get { return CommandType.NonDisturbing; }
        }

        public void Execute(object target, params object[] parameters)
        {
            if (!(target is DesignerCanvas))
            {
                throw new InvalidCastException("The target must be a DesignerCanvas");
            }
            this.designerCanvas = (DesignerCanvas)target;

            IEnumerable<DesignerItem> selectedDesignerItems =
                this.designerCanvas.SelectionService.CurrentSelection.OfType<DesignerItem>();

            XElement designerItemsXML = DocumentSerializationService.SerializeDesignerItems(selectedDesignerItems);

            XElement root = new XElement("Root");
            root.Add(designerItemsXML);

            root.Add(new XAttribute("OffsetX", 10));
            root.Add(new XAttribute("OffsetY", 10));

            Clipboard.Clear();
            Clipboard.SetData(DataFormats.Xaml, root);
        }

        public void Redo()
        {
            // Nothing to do
        }

        public void Undo()
        {
            // Nothing to do
        }

    }
}
